﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _14_超市收银系统
{
    class CangKu
    {
        //存储货架、货架里是各种货物
        List<List<ProductFather>> list = new List<List<ProductFather>>();

        /// <summary>
        /// 向用户展示货物
        /// </summary>
        public void ShowPros()
        {
            foreach (var item in list)
            {
                Console.WriteLine("我们超市有:" + item[0].Name + "\t" + item.Count + "个，\t每个" + item[0].Price + "元");
            }
        }

        /// <summary>
        /// 创建仓库的时候，里面已经有货架了,使用构造函数,一次添加四个货架
        /// list[0]存储Acer电脑
        /// list[1]存储三星手机
        /// list[2]存储酱油
        /// list[3]存储香蕉
        /// </summary>
        public CangKu()
        {
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
            list.Add(new List<ProductFather>());
        }

        /// <summary>
        /// 进货
        /// </summary>
        /// <param name="strType">货物的类型</param>
        /// <param name="count">货物的数量</param>
        public void JinPros(string strType, int count)
        {
            for (int i = 0; i < count;  i++)
            {
                switch (strType)
                {
                    case "Acer":
                        list[0].Add(new Acer(Guid.NewGuid().ToString(), 1000, "宏基笔记本"));
                        break;
                    case "SamSung":
                        list[1].Add(new SamSumg(Guid.NewGuid().ToString(), 2000, "三星手机"));
                        break;
                    case "Banana":
                        list[2].Add(new Banana(Guid.NewGuid().ToString(), 50, "香蕉"));
                        break;
                    case "JiangYou":
                        list[3].Add(new JiangYou(Guid.NewGuid().ToString(),10, "酱油"));
                        break;
                }
            }
        }

        public ProductFather[] QuPros(string strType, int count)
        {
            ProductFather[] pros = new ProductFather[count];
            for (int i = 0; i < count; i++)
            {
                switch (strType)
                {
                    case "Acer":
                        pros[i] = list[0][0];//取货,list[0]代表宏基笔记本货架,list[0][0]代表其中的一台笔记本
                        list[0].RemoveAt(0);//取完货物后删除该货物
                        break;
                    case "SamSung":
                        pros[i] = list[1][0];//取货,list[1]代表三星手机,list[1][0]代表其中的一台手机
                        list[1].RemoveAt(0);//取完货物后删除该货物
                        break;
                    case "Banana":
                        pros[i] = list[2][0];
                        list[2].RemoveAt(0);
                        break;
                    case "JiangYou":
                        pros[i] = list[3][0];
                        list[3].RemoveAt(0);
                        break;
                }
            }
            return pros;
        }
    }
}
